package com.yupi.springbootinit.service.impl;

import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.springbootinit.api.AliAPI;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.model.entity.Chart;
import com.yupi.springbootinit.service.ChartService;
import com.yupi.springbootinit.mapper.ChartMapper;
import com.yupi.springbootinit.utils.AliResponseUtils;
import com.yupi.springbootinit.utils.ExcelUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 *
 */
@Service
@Slf4j
public class ChartServiceImpl extends ServiceImpl<ChartMapper, Chart>
    implements ChartService{
    /**
     * 保存图表数据
     * @param chartType
     * @param goal
     * @param loginUserId
     * @param name
     * @param csv
     * @return
     */
    public Chart saveData(String chartType, String goal, Long loginUserId, String name, String csv){
        Chart chart = Chart.builder()
                .chartType(chartType)
                .status("wait")
                .goal(goal)
                .userId(loginUserId)
                .chartData(csv)
                .name(name)
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        try {
            this.save(chart);
        } catch (Exception e) {
            log.error("用户:"+loginUserId + "图表保存失败");
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "图表保存失败");
        }
        return chart;
    }
}




